﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1.DesignerPatter.Factory.SimpleFactory
{
    public class Operate
    {
        private double a, b;
        public double GetNumA
        {
            get { return a; }
            set { a = value; }
        }

        public double GetNumB
        {
            get { return b; }
            set { b = value; }
        }

        public virtual double GetResult()
        {
            return 0d;
        }
    }

    internal class Add:Operate
    {
        public override double GetResult()
        {
            return base.GetNumA + base.GetNumB;
        }
    }

    internal class Subtract : Operate
    {
        public override double GetResult()
        {
            return base.GetNumA-base.GetNumB;
        }
    }

    public class SimpleFactory
    {
        public static Operate CreateOperate(string operation)
        {
            Operate op = null;
            switch (operation)
            { 
                case "+":
                    op = new Add();
                    break;
                case "-":
                    op = new Subtract();
                    break;
            }
            return op;
        }

        public static void Main()
        {
            //Console.Write("请输入数字a:");
            //string a = Console.ReadLine();
            //Console.Write("请选择符号(+,-,*,/):");
            //string operate = Console.ReadLine();
            //Console.Write("请输入数字b:");
            //string b = Console.ReadLine();
            //Console.WriteLine("a{1}b={0}",GetResult(double.Parse(a),double.Parse(b),operate),operate);
            string operation = "-";
            Operate op = CreateOperate(operation);
            op.GetNumA = 2;
            op.GetNumB = 7;
            Console.WriteLine("a{0}b={1}", operation, op.GetResult());
            Console.Read();
        }

        public static double GetResult(double a, double b, string operate)
        {
            double result = 0d;
            switch (operate)
            {
                case "+":
                    result = a + b;
                    break;
                case "-":
                    result = a - b;
                    break;
                case "*":
                    result = a * b;
                    break;
                case "/":
                    result = a / b;
                    break;
            }
            return result;
        }
    }
}
